package com.haiyi.activiti.engine.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
 * <p> </p>
 *
 * <pre> Created: 2018/12/4 17:33 </pre>
 *
 * @author hlu
 * @version 1.0
 * @since JDK 1.7
 */
@Component
public class SpringHolder implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringHolder.applicationContext = applicationContext;
    }

    public static <T> T getBean(Class<T> clazz){
        Assert.notNull(applicationContext,"application装载失败！");
        return applicationContext.getBean(clazz);
    }
}
